import 'package:freezed_annotation/freezed_annotation.dart';

import 'tag_detail.dart';

part 'user_info_model.freezed.dart';
part 'user_info_model.g.dart';

@freezed
class UserInfoModel with _$UserInfoModel {
  factory UserInfoModel({
    int? age,
    int? auditStatus,
    int? availableCoins,
    String? avatar,
    String? avatarMiddleThumbUrl,
    String? avatarThumbUrl,
    String? avatarUrl,
    String? birthday,
    String? country,
    int? createTime,
    int? followNum,
    int? gender,
    int? giftWallAction,
    bool? hasEquity,
    bool? isAnswer,
    bool? isBlock,
    bool? isHavePassword,
    bool? isInternal,
    bool? isMultiple,
    bool? isRecharge,
    bool? isReview,
    bool? isSwitchNotDisturbCall,
    bool? isSwitchNotDisturbIm,
    bool? isVip,
    int? level,
    String? loginPkgName,
    String? nickname,
    int? praiseNum,
    String? registerCountry,
    String? registerPkgName,
    List<TagDetail>? tagDetails,
    List<String>? tagsList,
    String? userId,
    int? userType,
  }) = _UserInfoModel;

  factory UserInfoModel.fromJson(Map<String, dynamic> json) =>
      _$UserInfoModelFromJson(json);
}

extension UserInfoModelExt on UserInfoModel {
  DateTime get birthdayDate {
    if (birthday != null && birthday!.split('-').length == 3) {
      final List<String> list = birthday!.split('-');
      return DateTime(
          int.parse(list[0]), int.parse(list[1]), int.parse(list[2]));
    }
    return DateTime(1990, 01, 01);
  }
}
